<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="com.oreilly.servlet.MultipartRequest" %>
<%@ page import="com.oreilly.servlet.multipart.DefaultFileRenamePolicy" %>
<%@ page import="java.io.*" %>
<%@ page import="java.util.*" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ include file="/admin/common/inc/incSession.jsp" %>
<%

	RequestDispatcher rd = null;
	int result = 0;
	String thumbImg = "";
	String detailImg = "";
	File file = null;
	
	
	String realPath = ""; 			
	String savePath = "uploads/event"; 	// 업로드 경로명.
	String saveFolder = new SimpleDateFormat("yyyyMMdd").format(new Date());	// 날짜별로 폴더 생성
	
	ServletContext context = getServletContext();
	realPath = context.getRealPath(savePath+"/"+saveFolder);
	
	
	
	File fPath = new File(realPath); //경로생성

	 if ( !fPath.exists() ) {
		 fPath.mkdirs(); //상위 디렉토리가 존재하지 않으면 상위디렉토리부터 생성.
	 }

	Enumeration files = null;
	
	int maxSize = 10 * 1024 * 1024; // 최대 업로드 파일 크기 5MB
	
	try {
		
		
		MultipartRequest multi = new MultipartRequest(request, realPath, maxSize, "UTF-8", new DefaultFileRenamePolicy());
		
		 
		thumbImg = multi.getFilesystemName("thumbImg");	// 썸네일 이미지 파일 명
		detailImg = multi.getFilesystemName("detailImg"); 	// 상세 이미지 파일 명
		 
		 
		files = multi.getFileNames();
		String name = (String)files.nextElement();         
		file = multi.getFile(name);
		 
		if ( null != (thumbImg)) {
			
			param.put("thumb_img",savePath+"/"+saveFolder+"/"+thumbImg);
		 
		} 
		
		if( null != (detailImg)) {
			
			param.put("detail_img",savePath+"/"+saveFolder+"/"+detailImg);
		}

		String event_id = multi.getParameter("eventId");
		String event_type = multi.getParameter("eventType");
		String category_code = multi.getParameter("categoryCode");
		String event_name = multi.getParameter("eventName");
		String description = multi.getParameter("description");
		String product_name = multi.getParameter("productName");
		String link = multi.getParameter("link");
		String recruit_no = multi.getParameter("recruitNo");
		String req_fdate = multi.getParameter("reqFdate").replaceAll("-","");
		String req_tdate = multi.getParameter("reqTdate").replaceAll("-","");
		String win_date = multi.getParameter("winDate").replaceAll("-","");
		String review_fdate = multi.getParameter("reviewFdate").replaceAll("-","");
		String review_tdate = multi.getParameter("reviewTdate").replaceAll("-","");
		String provide_date = multi.getParameter("provideDate").replaceAll("-","");
		String smart_yn = multi.getParameter("smartYn");
		String use_yn = multi.getParameter("useYn");
		
		param.put("event_id",event_id);
		param.put("event_type",event_type);
		param.put("category_code",category_code);
		param.put("event_name",event_name);
		param.put("description",description);
		param.put("product_name",product_name);
		param.put("link",link);
		param.put("recruit_no",recruit_no);
		param.put("req_fdate",req_fdate);
		param.put("req_tdate",req_tdate);
		param.put("win_date",win_date);
		param.put("review_fdate",review_fdate);
		param.put("review_tdate",review_tdate);
		param.put("provide_date",provide_date);
		param.put("smart_yn",smart_yn);
		param.put("use_yn",use_yn);
		
		
		
			
		result = sqlMap.update("AdminEvent.updateEvent",param);
		
		
		if(result > 0 ){
			
			out.print("<script>alert('이벤트 수정을 성공하였습니다.');</script>");
			out.print("<script>parent.location.href = 'eventDetail.jsp?eventId="+event_id+"'</script>");
			
		} else {
			
			throw new Exception();
		}

	} catch (Exception e) {
			out.print("<script>alert('이벤트 수정에 실패하였습니다.');</script>");
		    e.printStackTrace();
	}
%>